package data;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import android.app.Activity;

/**
 * This class locks and account
 * 
 * @author Stephen Pardue
 * 
 */
public class LockAccount extends DBBooleanTask<Account> {

	/** if the account should be locked */
	private boolean isLocked;

	/**
	 * Creates a LockAccount task
	 * 
	 * @param activity
	 *            - the activity to show the task bar
	 * @param account
	 *            - the account to remove
	 * @param isLocked
	 *            - if the account should be locked
	 * @throws DBInterfaceError
	 *             - the error to throw
	 */
	public LockAccount(Activity activity, Account account, boolean isLocked)
			throws DBInterfaceError {
		super(activity, account);

		this.isLocked = isLocked;
	}

	/**
	 * Do the task
	 * 
	 * @param data
	 *            - the account to change
	 */
	@Override
	protected boolean task(Account data) {
		boolean success = false;
		try {
			PreparedStatement editAccount = conn
					.prepareStatement("UPDATE account SET locked=?, loginTimes='0' WHERE accountName=?");
			editAccount.setBoolean(1, isLocked);
			editAccount.setString(2, data.getAccountName());
			editAccount.execute();
			success = true;
		} catch (SQLException e) {
			success = false;
			e.printStackTrace();
		}

		return success;
	}

}
